<template>
  <div>
    <div>
      <el-row style="margin-bottom:10px">
        <el-col :span="8" >
          <h4 style="margin:0">
            <span>用户管理</span>
            <el-button  type="primary" class="addBtn" @click="addUserFun" v-if="userRole.MG_401001"><i class="el-icon-plus"></i>管理员用户</el-button>
          </h4>
        </el-col>
        <el-col :span="16" style="text-align:right">
          
        </el-col>
      </el-row>
     
      <el-table :data="tableData" border style="width: 100%" @selection-change="handleSelectionChange">
        
        <el-table-column prop="name" label="序号" width="60">
          <template slot-scope="scope">{{scope.$index+1}}</template>
        </el-table-column>
        <el-table-column prop="created_at" label="注册时间">
          <template slot-scope="scope">{{timeFun(scope.row.created_at)}}</template>
        </el-table-column>      
        <el-table-column prop="username" label="账号"></el-table-column>
        <el-table-column prop="nick" label="昵称"></el-table-column>
        <el-table-column prop="nick" label="状态" width="120">
          <template slot-scope="scope">
            <span v-if="scope.row.available_state==1">启用</span>
            <span v-else style="color:red">禁用</span>
          </template>
        </el-table-column>

        <el-table-column width="130" label="操作"> 
          <template slot-scope="scope">
            <div>
              <el-button class="addBtn" @click="showUserList(scope.row)" v-if="userRole.MG_401002">编辑</el-button> 
              <el-button v-if=" userRole.MG_401003" class="addBtn" type="danger" @click="deleteUser(scope.row.id)"> 删除</el-button>
              <!-- <el-button v-if="scope.row.available_state==1 && userRole.MG_401003" class="addBtn" type="danger" @click="disableUser(scope.row.id)"> 禁用</el-button>
              <el-button v-if="scope.row.available_state==0 && userRole.MG_401004" class="addBtn" type="primary" @click="enableUser(scope.row.id)"> 启用</el-button> -->
            </div>
          </template>
        </el-table-column>
      </el-table>
      <div class="block">
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="currentPage4"
          :page-sizes="[10, 20, 30, 50]"
          :page-size="10"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total">
        </el-pagination>
      </div>
    </div>

    
  
   <Adduser v-if="dialogVisible"  :dialogVisible="dialogVisible" ref="adduser"  :userData="userData"  @showFun ="closeVisible"></Adduser>
   
  </div>
</template>

<script>
  import Adduser from './content/Adduser'
  import Http from '@/Http/Http'
  import getTime from '@/Http/getTime'
  export default {
    data() {
      return {
        userRole:JSON.parse(sessionStorage.getItem('userSolt')),
        adduserSta:false,
        dialogVisible:false,
        userData:'',
        seachType:'',
        keyword:'',
        tableData: [],
        total:0,
        currentPage4: 1,//分野
        pageIndex:1,
        pageSize:10,
      }
    },
    components:{
      Adduser,
    },
    created() {
      this.getlist()
    },
    methods: {
      getlist() {
        Http.MonitorList(this.pageIndex,this.pageSize)
        .then( res => {
          this.tableData = res.data.data.rows
          this.total = res.data.data.total
          this.dataViedo='';
          this.editStatus = false
        })
        .catch( error => {
          
        })
       
      },
      timeFun(val) {
        return getTime(val)
      },

     
      showUserList(row) {
        this.dialogVisible = true;
        this.userData = row;
      },
       getdata (evt) {
        },
        datadragEnd (evt) {
            evt.preventDefault();
            
        },
      deleteUser(row){
        
        this.$confirm('确定删除此用户吗？','提示',{
          confirmVuttonText:'??',
          confirmButtonText:'确定'
        }).then( ()=> {
          Http.deleteMonitor(row)
          .then(res => {
            if(res.data.code == 200 ) { 
              this.$message.success('用户删除成功')
              this.getlist()
            }
          })
        }).catch( ()=> {
          
        })
      },
      disableUser(row) {  
        this.$confirm('确定禁用此用户吗？','提示',{
          confirmVuttonText:'??',
          confirmButtonText:'确定'
        }).then( ()=> {
          Http.disableMonitor(row)
          .then(res => {
            if(res.data.code == 200 ) { 
              this.$message.success('用户禁用成功')
              this.getlist()
            }
          })
        }).catch( ()=> {
          
        })
      },
      enableUser(row) { 
        this.$confirm('确定启用此用户吗？','提示',{
          confirmVuttonText:'确定',
          confirmButtonText:'确定'
        }).then( ()=> {
          
          Http.enableMonitor(row)
          .then(res => {
            if(res.data.code == 200 ) { 
              this.$message.success('用户启用成功')
              this.getlist()
            }
          })
        }).catch( ()=> {
          
        })
      },
      
       //添加用户
      addUserFun() {
        this.dialogVisible = true;
        this.adduserSta = true;
      },
     
      closeVisible() {
        this.dialogVisible = false;
        this.adduserSta = false;
        this.userData ='';
        this.getlist()
      },
     
      //选择 推荐
      handleSelectionChange() {
        
      },
      handleClose(done) {
        this.$confirm('确认关闭？')
          .then(_ => {
            done();
          })
          .catch(_ => {});
      },
       //搜索
      sheachFun(){
        this.getlist()
      },
       //分页
      handleSizeChange(val) {
        this.pageSize = val;
        this.getlist()
        
      },
      handleCurrentChange(val) {
        this.pageIndex = val;
        this.getlist()
        
      },
    }
  }
</script>
<style  scoped>
.box{
  border-bottom:1px solid red;
}
    .test{
        border:1px solid #ccc;
    }
    .drag-item{
        width: 200px;
        height: 50px;
        line-height: 50px;
        margin: auto;
        position: relative;
        
        background: #ddd;
        margin:20px 5px;
    }
    .ghostClass{
        opacity: 1;
    }
    .bottom{
        width: 200px;
        height: 50px;
        position: relative;
        background: blue;
        top:2px;
        left: 2px;
        transition: all .5s linear;
    }
</style>
